package com.msos.service.reChargeService;

import com.msos.dao.reChargeDao.reChargeDao;
import com.msos.model.ReCharge.ReCharge;
import com.msos.utils.CommonsUtils;

import java.sql.SQLException;
import java.util.List;

public class reChargeService {
    //1.此卡号是否已存在
    //2.添加卡号
       reChargeDao rechargeDao=new reChargeDao();
    public Integer addReCharCard(String cardNumber, String password,String endDate) {
        ReCharge reCharge= null;
        try {
            reCharge = rechargeDao.getReCharByNum(cardNumber);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(reCharge!=null){
            return CommonsUtils.EXIST;
        }
        Integer r1= null;
        try {
            r1 = rechargeDao.addReCharge(cardNumber,password,endDate);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return r1==1?CommonsUtils.SUCCESS:CommonsUtils.FAIL;
    }

    public List<ReCharge> getAllCard() {
        try {
            return rechargeDao.getAllCard();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Integer recharCardsDelete(String[] ridList) {
        Integer r1=CommonsUtils.EXCEPTION;
        try {
            r1=rechargeDao.recharCardsDele(ridList);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return r1;
    }
}
